// promise.all


// Promise.resolve如果参数是 Promise 实例，那么Promise.resolve将不做任何修改、原封不动地返回这个实例。



Promise.myall = function(promises) {
    return new Promise((resolve, reject) => {
        let len = promises.length
        let result = []
        let count = 0
        if(len == 0) {
            resolve(result)
            return
        }

        for (let i = 0; i < len; i++) {
            Promise.resolve(promises[i]).then(data => {
                result[i] = data
                count +=1
                if(count == len) {
                    resolve(result)
                }
            }).catch(err => {
                reject(err)
            })
        }
    })
}

let a = function() {
    return new Promise((resolve, rejected) => {
        console.log('123');
        setTimeout(() => {
            resolve('333')
        }, 1000)
    })
}

let b = function() {
    return new Promise((resolve, rejected) => {
        console.log('123');
        setTimeout(() => {
            resolve('333')
        }, 1000)
    })
}



// pro.then(res => {
//     console.log(res);
// })

Promise.myall([a(), b()]).then(res => {
    console.log(res);
})